package com.hbnu.exercise.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServerDemo02
{
    public static void main(String[] args)
    {
        try
        {
            ServerSocket serverSocket = new ServerSocket(8888);

            Socket socket = serverSocket.accept();

            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();

            byte[] data = new byte[1024];
            int length = in.read(data);

            System.out.println(new String(data, 0, length));

            out.write("收到, OVER!".getBytes());

            serverSocket.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
